<?php 
/** 
* $image image cursor (from imagecreatetruecolor) 
* $backgound image curosr (from imagecolorallocate) 
* $paddng int 
*/ 

header('Content-type: image/jpeg');

$res1 = imageCreateFromjpeg("./face.jpg");
// $img = imageCrop($res1,array('x'=>50,'y'=>50,'width'=>200,'height'=>200));


 $img = imagecreatetruecolor($right-$left+$padding*2,$bottom-$top+$padding*2); 
    // fill the background 
    imagefill($img, 0, 0, $background); 
    // copy 
    imagecopy($img, $image, $padding, $padding, $left, $top, $right-$left, $bottom-$top); 

imagejpeg($img);

?>